<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>数组大小减半</title>
</head>
<body>
  <script>
    function fn(arr) {
      let res = 0; hash = {};
      for (let i of arr) {
        hash[hash[i] ? hash[i]++ : hash[i] = 1];
      }
      let tmp = Object.values(hash).sort((a, b) => b - a);
      for (let j = 0; j < tmp.length; j++) {
        res += tmp[j];
        if (res >= arr.length / 2) return j + 1;
      }
    }
    console.log(fn([3, 3, 3, 3, 5, 5, 5, 2, 2, 7]))
  </script>
</body>
</html>